package com.cc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cc.service.GoodsService;
import com.cc.mapper.GoodsMapper;
import com.dy.cc.Goods;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Lenovo
 * @description 针对表【goods】的数据库操作Service实现
 * @createDate 2024-11-20 10:07:40
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
        implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;



    @Override
    public List<Goods> price(Goods goods, Integer a,Integer uid) {

        // loginUid 是获取的登录人的 uid
        Integer loginUid = uid; // 需要实现这个方法来获取登录人的 uid

        if (loginUid != null && loginUid.equals(uid)) {
            LambdaQueryWrapper<Goods> lam = new LambdaQueryWrapper<>();
            lam.eq(Goods::getUid, uid);

            System.out.println("-----------------------------" + a);
            if (a == 1) {
                lam.orderByAsc(Goods::getScore2);
            } else {
                lam.orderByDesc(Goods::getScore2);
            }
            return baseMapper.selectList(lam);
        } else {
            // 如果登录人的 uid 不等于传递过来的 uid，可以选择返回空列表或其他默认行为
            return Collections.emptyList();
        }
    }

    @Override
    public List<Goods> sousuo(Goods goods) {
        return goodsMapper.sousuo(goods);
    }

    @Override
    public List<Goods> find(Integer uid) {
        return goodsMapper.find(uid);
    }

    @Override
    public List<Goods> All(Goods goods, Integer uid) {
        return goodsMapper.All(goods, uid);
    }

    @Override
    public List<Goods> findList(Goods goods) {
        return goodsMapper.findList(goods);
    }


    @Override
    public List<Goods> findAll(Goods goods) {
        return goodsMapper.findAll(goods);
    }

    @Override
    public List<Goods> xiao(Integer uid) {
        return goodsMapper.xiao(uid);
    }

    @Override
    public List<Goods> shang(Integer uid) {
        return goodsMapper.shang(uid);
    }

    @Override
    public List<Goods> fAll(Goods goods) {
        return goodsMapper.fAll(goods);
    }

    @Override
    public List<Goods> priceAll(Goods goods, Integer a) {
        LambdaQueryWrapper<Goods> lam = new LambdaQueryWrapper<>();

        System.out.println("-----------------------------" + a);
        if (a == 1) {
            lam.orderByAsc(Goods::getScore2);
        } else {
            lam.orderByDesc(Goods::getScore2);
        }
        lam.last("LIMIT 3");
        return baseMapper.selectList(lam);
    }

    @Override
    public List<Goods> xiaoAll(Goods goods) {
        return goodsMapper.xiaoAll(goods);
    }

    @Override
    public List<Goods> shangAll(Goods goods) {
        return goodsMapper.shangAll(goods);
    }
}
